package com.sh.config.mybatis_plus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

/**
 * @Auther: 世豪学java
 * @Date: 2023/12/13 - 12 - 13 - 18:01
 * @Decsription: com.sh.config.mybatis_plus
 * @version: 1.0
 */
/*
*
*   元数据处理器，在数据库添加，修改数据时添加时间
*
* */
@Repository
@Slf4j
public class MyBatisPlusHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime",LocalDateTime.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ...");
        this.setFieldValByName("updateTime",LocalDateTime.now(),metaObject);
    }
}
